<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp"%>
<html>
  <head>
	<title>公共平台 </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!-- 样式文件的引入 -->
	<link href="${ctx}/commons/css/style.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/icon.css">
	<!-- 富文本样式 -->

	<!-- jqueryUI JS文件的引入 -->
	<script type="text/javascript" src="${ctx}/commons/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${ctx}/commons/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/commons/js/easyui-extends-validate.js"></script>
	<!-- jqueryUI国际化 -->
	<script type="text/javascript" src="${ctx}/commons/js/easyui-lang-zh_CN.js"></script>
	<!-- 开发使用的公用js方法 -->
	<script type="text/javascript" src="${ctx}/commons/js/common.js"></script>

	<script type="text/javascript" src="${ctx}/c2c/Public/Js/moment.min.js"></script>

	<!-- 引入富文本框 -->
	<script type="text/javascript" src="${ctx}/commons/tinyeditor/tinyeditor.js"></script>

	<!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
	<script type="text/javascript">var ctx = '${ctx}';var actionExt = "action";var i18n = new Object();</script>
	<script src="${ctx}/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
  </head>

  <body>
    <div class="easyui-layout" data-options="fit:true,border:false" >
       <div class="easyui-layout" data-options="fit:true,border:false" >
				<div data-options="region:'north',border:false" style="padding: 4px;height: 50px;overflow: hidden;">
					<div class="easyui-panel" data-options="fit:true,border:true" >
						<div  class="queryContent">
							<form name="searchForm" id="searchContentForm" method="post" action="" style="display: none; ">
								<table class="queryTable" >
									<tbody>
										<tr>
											<th width="80%">标题</th>
											<td width="10%">
											<input class="easyui-validatebox" type="text" name="title" maxlength="20" style="width:120px"></input></td>
											<th>类型名称</th>
											<td width="10%">
												<input id="type" name="type"/>
											</td>
											<th>添加时间 </th>
											<td width="10%">
												  <input id="startTime" class="easyui-datebox" type="text" name="startTime"  data-options="validType:['dateTimeLessCompare[\'endTime\']']" maxlength="20" style="width:140px"/>-<input id="endTime" class="easyui-datebox" type="text"  data-options="validType:['dateTimeMoreCompare[\'startTime\']']" name="endTime" maxlength="20" style="width:140px"/></td>
											</td>
											<td align="right" width="10%"><a href="javascript:void(0);" class="easyui-linkbutton" id="searchContent" plain="true">查询</a>
											<a href="javascript:void(0);" class="easyui-linkbutton" id="resetSearchContent" plain="true">清空</a></td>
										</tr>
									</tbody>
								</table>
							</form>
						</div>
					</div>
				</div>

	   <div data-options="region:'center',border:false" style="padding: 4px;">
		    <table id="listContentTable" class="easyui-datagrid"
				data-options="singleSelect:false,toolbar:'#tb',method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
					pagination:true,remoteSort:true,multiSort:true,striped:true,onLoadSuccess:function(data){$('#'+paramObj.searchID).attr('disabled',false);},
					url:'${ctx}/business/webcontent/list'"}>
				<thead>
					<tr>
						<th data-options="field:'id',checkbox:true"></th>

                        <th data-options="field:'title',width:80,sortable:true,formatter: function(value,row,index){
								return '<a href=javascript:void(0);  onclick=openDataDialog(paramObj,\''+row.id+'\',undefined) >'+value+'</a>';
							},title:'标题'"></th>
						<th data-options="field:'typeName',width:100,title:'文章分类'"></th>
					    <th data-options="field:'disSort',width:20,title:'排序值'" align="right"></th>
					    <th data-options="field:'isDisplay',width:50,title:'是否显示',formatter:function(value,row,index){if(value=='0')return '是';else return '否';}" align="center"></th>
			            <th data-options="field:'confirmTime',sortable:true,width:50,title:'中标结果确认时间'" align="center"></th>
						<th data-options="field:'createTime',sortable:true,width:50,title:'添加时间'" align="center"></th>
						<th data-options="field:'opt',sortable:true,width:50,title:'详情',formatter:getOpt" align="center"></th>
					</tr>
				</thead>
			</table>
			<div id="tb" style="display: none;">
				<div>
					<a href="javascript:void(0);" onclick="openDataDialog(paramObj,undefined,undefined);" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
					<a href="javascript:void(0);" onclick="updateData(paramObj,undefined);" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
					<a href="javascript:void(0);" onclick="deleteData(paramObj,undefined);" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
				</div>
			</div>
		</div>
	    </div>
	 <div id="shoContentDialog"></div>
	</div>
	<script type="text/javascript">
		//初始化表格对应的js对象
		var paramObj;
		$(function() {
			//初始化表格对象数据
			paramObj = new initParams(
					{
						paramObjName : 'paramObj',//表格对应的实体对象名称，好区分多个表格情况下的对象
						tableId:'listContentTable',
						addDataFormId:'addContentDataForm',
						showDialogId:'shoContentDialog',
						searchID:'searchContent',
						resetSearchID:'resetSearchContent',
						searchFormID:'searchContentForm',
						updateUrl:'${ctx}/business/webcontent/input?id=',
						deleteUrl:'${ctx}/business/webcontent/remove',
						addDialogWidth:980,
						addDialogHeight:600,
						ctx:'${ctx}',
						addDialogTitle:'文章信息'
					});
			//初始化查询
			init(paramObj);
			//绑定文章类型菜单
			bindWebType();
		});


		/**
		*操作
		*/
		function getOpt(value, row, index){
			var html = '<a href="${ctx}/web/getWebDetail?id='+row.id+'" target="_bank">详情</a>&nbsp;';
			return html;
		}


		function bindWebType(){

		$('#type').combobox({
             url:'${ctx}/business/webcontent/typeListFromSearch?t='+new Date().getTime(),
                valueField:'id',
                textField:'name',
                onLoadSuccess: function () { //加载完成后,设置选中第一项
                var val = $(this).combobox("getData");

                for (var item in val[0]) {
                    if (item == "id") {
                        $(this).combobox("select", "--请选择类型--");
                    }
                  }
                 }
               });
		}

		function bindArticleType(){
		  $.ajax({
		   url:'${ctx}/business/webtypemanage/listAll?t='+new Date().getTime(),
		   type:'post',
		   success:function(data){
		    var opt='';
		    for(var i=0;i<data.length;i++){
		      if(data[i].id=="1") continue;
		      opt+='<option value="'+data[i].id+'">'+data[i].name+'</option>';
		    }
		     $('select[name=type]').append(opt);
		   },
		   error:function(){

		   }
		  });
		}

		/**
		 * 打开添加数据的页面的对话框
		 * @param {Object} paramObj ： 对应的列表对象
		 * @param {Object} id ： 数据记录的ID
		 * @param {Object} successcallback ：添加数据成功后的回调函数
		 * @param {Object} failurecallback ： 添加数据失败后的回调函数
		 */
	function openDataDialog(paramObj,id,successcallback,failurecallback){
			if(id == undefined){
				id='';
			}
			var sign = false;
			top.$('#firstLevelDialog').dialog({
			    title:paramObj.addDialogTitle,
			    iconCls:'icon-view',
			    width: paramObj.addDialogWidth,
			    height: paramObj.addDialogHeight,
			    closed: false,
			    inline : true,
			    cache: false,
			    href: paramObj.updateUrl+id,
			   // href: "http://localhost/e_shop/ueditor/index.html" ,
			    modal: true,
				extractor : function(data){
					if($.trim(data) == "unLogin"){
						var msn = ''||i18n[''];
						msn = msn||i18n[data];
						if(msn != undefined){
							top.$.messager.alert('提示',msn,'info',function(){top.location=paramObj.ctx+'/manage';});
							return '';
						}
					}
					return data;
				},
			    buttons : [{text:paramObj.saveButton,
			    		id:'saveEntityBt',
						iconCls:'icon-ok',
						handler:function(){
							saveEntity(paramObj,'saveEntityBt',successcallback,failurecallback);
						}
					},{
						text:paramObj.cancelButton,
						iconCls:'icon-cancel',
						handler:function(){
							top.$('#firstLevelDialog').dialog('close');
						}}]
			});
			top.$('#firstLevelDialog').dialog("center");
		}
		/**
 * 添加、更新保存数据
 * @param {Object} paramObj:表格对应的初始化对象
 * @param {Object} opBtId: 代表保存数据按钮对应的ID，进行防止重复提交的作用
 * @param {Object} successcallback：在调用添加成功后调用的初始化回调方法
 * @param {Object} failurecallback：在调用添加失败后调用的初始化回调方法
 */
function saveEntity(paramObj,opBtId,successcallback,failurecallback){
	    if($.trim(top.$('#newTitle').val()) == ""){
             top.$.messager.alert('提示',"标题不能为空");
             return;
	    }

	    //被校验曝光人是否存在
	    var bidderName=top.$('#exploreUserId').combobox('getValue');
	    var typeId=top.$("#type").combobox('getValue');
	    //alert(top.$('#exploreUserName').combobox('getValue'));
	    var result=false;
	    if(typeId=="53"){//为曝光类型
	    	$.ajax({
				type: "post",
				async:false,
				url: "${ctx }/validate/unique",
				data:'tableName=t_reg_user_info&field=id&value='+bidderName,
				success: function(data){
					if(data == "success"){
						result = true;//不存在
						top.$.messager.alert('提示',"该投标人不存在，请重新输入投标人全称！");
					}else {
						result = false;//存在
					}

				}
			});
	    }

	    if(result){
	    	return;
	    }

	    top.$('#contentMsg').val(top.getEditorHTMLContents());
	     var msn = ''||i18n[''];
	     debugger;
			//if(top.$('#'+paramObj.addDataFormId).form('validate')){

            var endShowTime = $.trim(top.$('#endShowTime').datebox('getValue'));

            if (moment(endShowTime).isValid()==false) {
                top.$.messager.alert('提示', "公示结束时间,时间格式不正确！", 'info', function () {
                });
                return;
            }

            // if () {
            //     top.$.messager.alert('提示', "公示结束时间,不能小于当前时间！", 'info', function () {
            //     });
            //     return;
            // }
            top.$('#'+opBtId).linkbutton('disable');
				$.ajax({
					type: "POST",
					timeout:20000,
					url:  top.$('#'+paramObj.addDataFormId).attr("action"),
					data:top.$("#"+paramObj.addDataFormId).serialize(),
					success: function(data,res){
						var result = $.trim(res.responseText);
						if(result == "unLogin"){
							var msn = ''||i18n[''];
							msn = msn||i18n[result];
							if(msn != undefined){
								top.$.messager.alert('提示',msn,'info',function(){top.location=paramObj.ctx+'/manage';});
								return ;
							}
						}
						msn = msn||i18n[data];
						if(msn == undefined){
							top.$.messager.alert('提示',i18n.serverError,'info');
						}else if(msn)	{
							top.$.messager.alert('提示',msn,'info',function(){$('#'+paramObj.tableId).datagrid('reload');top.$('#firstLevelDialog').dialog('close');});
						}
						if(successcallback != undefined){
							successcallback();
						}
					},
					error: function(res){
						top.$.messager.alert('提示',i18n.requestError,'error');
						top.$('#'+opBtId).linkbutton('enable');
						if(failurecallback != undefined){
							failurecallback();
						}
					}
				});
			//}
    }
	</script>
  </body>
</html>
